# -*- coding: utf-8 -*-
"""
实现工厂模式
"""
import logging

import py_global

logger = logging.getLogger(__name__)


class FactoryClass(object):
    factory_dict = dict()

    def __init_subclass__(cls, **kwargs):
        cls.factory_dict[cls.__name__] = cls
        pass

    def factory_method(self):
        logger.info(f'class:{self.__class__.__name__}')
        pass


class FactoryType0(FactoryClass):

    def factory_method(self):
        logger.info(f'class:{self.__class__.__name__}')
        pass


class FactoryType1(FactoryClass):

    def factory_method(self):
        logger.info(f'class:{self.__class__.__name__}')
        pass


if __name__ == '__main__':

    factory_list = ['FactoryType', 'FactoryType0', 'FactoryType1']
    for factory_name in factory_list:
        factory_class = FactoryClass.factory_dict.get(factory_name, FactoryClass)
        factory_class().factory_method()
        pass
    pass
